// import { getToken } from '@utils/request/auth'
import storage from '@utils/storage'

export default {
    state: {
        user: {},
        token: '',
        routes: []
    },
    mutations: {
        setUser(state, user) {
            state.user = { ...user, expired: (new Date()).addHours(3) }

            window.localStorage && localStorage.setItem('user', JSON.stringify({ ...state.user }))
        },
        clearUser(state) {
            state.user = {}
            window.localStorage && localStorage.removeItem('user')
        },
        setToken(state, token) {
            state.token = token
        },
        setRoutes(state, routes = []) {
            state.routes = routes
        }
    },
    actions: {
        initToken({ commit }, ticket, ticketType) {
            commit('setToken', ticket)
            storage.set('token', ticket)
            //使用公共接口时（ ticketType:-1为测试模式，0为门户轻应用，1为重药之家轻应用）
            // return getToken(ticket, ticketType).then(res => {
            //     if (res.success) {
            //         commit('setToken', res.token)
            //         storage.set('token', res.token)
            //     }

            //     return Promise.resolve(res)
            // })
        }
    }
}